/*
 * point.c
 *
 *  Created on: 5 Nov 2009
 *      Author: Marc Pluhar <marc.pluhar@stud.hs-esslingen.de>
 */

#include "point.h"

void Point_print(const Point* src) {
	if (src)
		printf("(%.2lf, %.2lf)", src->x, src->y);
}

void Point_printList(const List* src) {
	List* cur;
	Point_print(list_getPayload(src));
	if (list_getPayload(src)) printf("\n");
	cur = list_getNext(src);
	while(cur) {
		Point_print(list_getPayload(cur));
		if (list_getPayload(cur)) printf("\n");
		cur = list_getNext(cur);
	}
}

void Point_add(List* dest, const double x, const double y) {
	Point* newpoint;
	newpoint = (Point*) calloc(1, sizeof(Point));			/* Create new Point from parameters */
	newpoint->x = x;
	newpoint->y = y;
	list_addItem(dest, newpoint);							/* Append newly created Point to given List */
}

void Point_append(List* cur, const Point p) {
	Point* payload;
	payload = (Point*) calloc(1,sizeof(Point));
	payload->x = p.x;		/* Copy values from given Point to Payload */
	payload->y = p.y;
	list_addItem(cur, payload);
}
